<?php

/**
 * This is the model class for table "{{friendlink}}".
 *
 * The followings are the available columns in table '{{friendlink}}':
 * @property integer $zfl_id
 * @property integer $zlc_id
 * @property integer $zm_id
 * @property integer $zlc_type
 * @property string $zfl_title
 * @property string $zfl_logo
 * @property string $zfl_url
 * @property integer $zfl_listorder
 * @property integer $zfl_status
 * @property string $zfl_desc
 * @property integer $inputtime
 * @property integer $updatetime
 */
class Friendlink extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Friendlink the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{friendlink}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zlc_id, zfl_title, zfl_url', 'required'),
			array('zfl_url', 'url'),
			array('zlc_id, zm_id, zlc_type, zfl_listorder, zfl_status, inputtime, updatetime', 'numerical', 'integerOnly'=>true),
			array('zfl_title', 'length', 'max'=>100),
			array('zfl_logo, zfl_url', 'length', 'max'=>255),
			array('zfl_desc', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('zfl_id, zlc_id, zm_id, zlc_type, zfl_title, zfl_logo, zfl_url, zfl_listorder, zfl_status, zfl_desc, inputtime, updatetime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'zfl_id' => 'ID',
			'zlc_id' => '分类ID',
			'zm_id' => '会员ID',
			'zlc_type' => '类型',
			'zfl_title' => '链接标题',
			'zfl_logo' => 'LOGO地址',
			'zfl_url' => '链接地址',
			'zfl_listorder' => '排序',
			'zfl_status' => '状态',
			'zfl_desc' => '描述',
			'inputtime' => '发布时间',
			'updatetime' => '更新时间',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('zfl_id',$this->zfl_id);
		$criteria->compare('zlc_id',$this->zlc_id);
		$criteria->compare('zm_id',$this->zm_id);
		$criteria->compare('zlc_type',$this->zlc_type);
		$criteria->compare('zfl_title',$this->zfl_title,true);
		$criteria->compare('zfl_logo',$this->zfl_logo,true);
		$criteria->compare('zfl_url',$this->zfl_url,true);
		$criteria->compare('zfl_listorder',$this->zfl_listorder);
		$criteria->compare('zfl_status',$this->zfl_status);
		$criteria->compare('zfl_desc',$this->zfl_desc,true);
		$criteria->compare('inputtime',$this->inputtime);
		$criteria->compare('updatetime',$this->updatetime);

		$criteria->order = " inputtime DESC ";//默认为时间倒序
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public function getType($type=null){
		if($type==null){
			return array(
					'1'=>'文本',
					'2'=>'图片',
				);
		}
	}

	public function getStatus(){		
			return array(
					'1'=>'显示',
					'2'=>'隐藏',
				);		
	}

}